# -*- coding: utf-8 -*-
"""
Created on Fri Dec 17 10:23:08 2021

@author: wulong
"""
import numpy as np
from casadi import *

# In[1] real system
Nx_r = 23
Nuc_r = 6 # 6 continuous inputs
Nuz_r = 4 # 4 binary inputs
Nud_r = 4 # 4 disturbances
Nu_r = Nuc_r + Nuz_r # 6 manipulated input + 4 binary variables
Ny_r = 2 # 2 ouputs
Delta_r = 1

# system parameters
Cw = 4.2
eps = 1e-8 # positive infinite number to avoid calculation errors


# PV
npp = 35 # PV parallel
nsp = 6 # PV series
c_pv1 = 0.0025
c_pv2 = 0.000092
c_pv3 = 0.00413
V_max_0 = 29
I_max_0 = 7.412
Ins_pv_0 = 1000
T_pv_0 = 25


# FC
tau_e = 0.8
tau_f = 5
KO2 = 2.52
KH2O = 0.281
KH2 = 0.843
tau_O2 = 2.91
tau_H2O = 78.3
tau_H2 = 26.1

rfc = 0.126
afc = 0.05
bfc = 0.11
R0fc = 8.314
T0fc = 1273
F0 = 96485
IL = 800

Mch4 = 1000/16
Kr = 0.996e-3
N0fc = 384
E0fc = 1.18
fu_d = 0.8
r_HO = 1.145


# MA
Pmt0 = 80
tab0 = 7

tau_mtf = 20
tau_abf = 130
tau_abw = 80
tau_abt = 70

kma1 = -686180
kma2 = 2.14446e4
kma3 = -1.12767e2
kma4 = -3.86296e-2
kma5 = 1.24
kma6 = -4.4285
kma7 = 0.957
kma8 = -11.484


# EC
Aci = 2.4772; Aco = 2.8311; Aei = 2.6377; Aeo = 3.0145
alfar = 4.4760; alfaw = 5.0800
Ccr = 1.3390; Cer = 1.1750; Cs = 0.3940;
hspc = 2.6780; hsph = 1.4960; kr = 1.3880
Mcr = 9.7843; Mcs = 94.4869; Mcw = 79.7615
Mer = 11.7681; Mes = 100.6101; Mew = 71.3956
roeg = 22.6020; Vcp = 1.4215e-4
Gcw = 2.8323; tcwi = 28 # cooling water in condenser


# BA
Em = 50
R1b = 4.8e-3
R0b = 4.2e-2
C1b = 1296
npb = 4
nsb = 4
Ceb = 200
tau_dc = 0.8


# ST
Mst = 2e4 # Total water weight in tank
tsth0 = 12 # initial hot water temperature
tstc0 = 7 # initial chilled water temperature


# BR
Spmp = 5.1e4 # Pump
rhow = 1e3
ge = 9.8
b0p = -1.0066e-2
b1p = 1.3079e-1
b2p = 3.5522e-1

Qsl0 = 125 # AHU
delta_twa0 = 15
Gsl0 = 5.9524
tau_ahu = 20

Cbr = 5.14e4 # Building
Ubr = 4.0625

# time decomposition
tau_x2 = tau_f
tau_x9 = tau_abt
tau_x23 = Cbr/Ubr
epsilon_1 = tau_x2/tau_x23
epsilon_2 = tau_x9/tau_x23

# long-term coefficient
k_pv = 4.51391e-2
k_fc = 40/0.0045
k_mt = 80/0.0066911
k_ab = 75/80
k_ec = 50/110
k_cp = 12.6/50
k_st = 4.2*5
k_pmp = 13.9/5.9524
k_ba = -1.736111e-06
Gab0 = 3.5714
Gec0 = 2.381

# In[2] Long-term
Nx_l = 3
Nuc_l = 5
Nuz_l = 4
Nud_l = 3
Ny_l = 2
Delta_l = 3600

# In[3] Slow-MPC
Nx_s = 5
Nuc_s = 3
Nud_s = 4
Ny_s = 2
Delta_s = 120

# In[4] Medium-MPC
Nx_m = 9
Nuc_m = 1
Nud_m = 4
Ny_m = 2
Delta_m_temp = 8
Delta_m = Delta_m_temp/epsilon_2

# In[5] Fast-MPC
Nx_f = 9
Nuc_f = 2
Nud_f = 4
Ny_f = 2
Delta_f_temp = 2
Delta_f = Delta_f_temp/epsilon_1
